package main

import (
	"log"
	"myprotobuf/build/gen/myprotobuf/person"

	"google.golang.org/protobuf/proto"
)

func main() {
	/* ****************** proto 练习 ******************* */
	p := &person.Person{
		Name:  "guan",
		Id:    1234,
		Email: "hello@qq.com",
		Phones: []*person.Person_PhoneNumber{
			{Number: "123456", Type: person.Person_HOME},
		},
	}

	msgByte, err := proto.Marshal(p)
	if err != nil {
		log.Fatal("msg encode fail!")
	}

	log.Println(msgByte)

	p1 := &person.Person{}
	if err = proto.Unmarshal(msgByte, p1); err != nil {
		log.Fatal("msg decode fail!")
	}

	log.Println(p1)

}

